<%@ page language="java" contentType="text/html"  pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  <title>仿站</title> 
  <link rel="stylesheet" href="${APP}statics/tag/css/bootstrap.min.css"/>	
  <link rel="stylesheet" href="${APP}statics/tag/css/font-awesome.css"/>	
 </head> 
<body>	 
<div class="container-fluid">
	<div class="row">
	    <div class="col-xs-1"></div>
	    <div class="col-xs-10">
	        <div class="panel panel-default" style="margin-top:15px;">
			    <div class="panel-body" style="height:200px;overflow:hidden;" id="showmsg">			    
			    </div>
			</div>
			<h5>正在加载，请骚等。。。</h5>
			<div class="progress">
				<div id="progress" class="progress-bar progress-bar-primary progress-bar-striped active" role="progressbar" style="width:0%;">
					0%
				</div>
			</div>
			<div id="download">
				
			</div>
		</div>
		<div class="col-xs-1"></div>
	</div>
</div>
<script src="${APP}statics/tag/js/jquery-3.2.1.min.js"></script>
<script>
var url="${APP}";
var ws;
var target=url.substr(7,url.length);
target ="ws://"+target+"websocket/getPlagConnct";		
if ('WebSocket' in window) {
	ws = new WebSocket(target);			
} else if ('MozWebSocket' in window) {
	ws = new MozWebSocket(target);			
} else {
	alert("您的浏览器不支持websocket！");
}			
ws.onmessage = function(event) {
	eval("var obj="+event.data);
	if(obj.step==100 && obj.success==true){
		var h="${APP}flag/"+obj.msg.host+"/"+obj.msg.filename+".html";
		var s="${APP}index/lcfms/download?host="+obj.msg.host;
		var str="<a target=\"_blank\" href=\""+h+"\" class=\"btn btn-primary\">预览</a> <a target=\"_blank\" href=\""+s+"\" class=\"btn btn-primary\">下载</a>"
		$("#download").html(str);
	}else{
		if(obj.success==true){
			$("#showmsg").prepend("<span style='color:green;'>"+obj.msg+"</span><br/>");
		}else{
			$("#showmsg").prepend("<span style='color:red;'>"+obj.msg+"</span><br/>");
		}				
	}
	$("#progress").width(obj.step+"%");
	$("#progress").html(obj.step+"%");	
};
ws.onopen = function(){
	console.log("websocket连接成功！");
};
ws.onclose = function(evt){
	console.log("websocket连接关闭！");
};
ws.onerror = function(evt){
	console.log("websocket连接错误！");
};	
</script>
</body>
</html>					